package com.study.day01;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.Settings;

import java.io.IOException;

public class ESTest_Index_Create {

    public static void main(String[] args) throws IOException {

        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost", 2001, "http"))
        );

        CreateIndexRequest user = new CreateIndexRequest("user");

        user.settings(Settings.builder().put("index.number_of_shards", 3) // 分片数
                .put("index.number_of_replicas", 2) // 副本数
                .put("analysis.analyzer.default.tokenizer", "ik_smart") // 默认分词器
        );


        CreateIndexResponse createIndexResponse =
                esClient.indices().create(user, RequestOptions.DEFAULT);


        System.out.println(createIndexResponse.isAcknowledged());

        try {
            esClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
